<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('用印申请') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请标题')" prop="actTitle">
        <el-input v-model="queryParams.actTitle" :placeholder="$t('申请标题')" size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('申请人')" prop="userName">
        <el-input v-model="queryParams.userName" :placeholder="$t('申请人')" clearable size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('申请时间')">
        <DatePicker
          v-model="dateRange"
          type="daterange"
        />

      </el-form-item>
      <el-form-item :label="$t('关联合同')" prop="contractAssociatedName">
        <el-input
          v-model="queryParams.contractAssociatedName"
          :placeholder="$t('关联合同')"
          clearable
          size="small"
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['oa:seal:edit']" type="primary" icon="el-icon-plus" size="mini" @click="addHandle">{{ $t("新增") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['oa:seal:export']" type="warning" icon="el-icon-download" size="mini" @click="exportHandle">{{ $t("导出") }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="oaSealList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" prop="actTitle" :show-overflow-tooltip="true" width="250">
        <template slot-scope="scope">
          <el-link v-if="scope.row.actId !== undefined && scope.row.actId !== null && scope.row.actId !== ''" type="primary" @click="startProcess(scope.row)">{{ scope.row.actTitle }}</el-link>
          <el-link v-else type="primary" @click="updateHandle(scope.row)">{{ scope.row.actTitle }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="userName" :show-overflow-tooltip="true" width="110" />
      <el-table-column :label="$t('申请时间')" align="center" prop="applyTime" show-overflow-tooltip width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('用印类型(一级)')" align="center" prop="usineTypeOneName" show-overflow-tooltip width="110">
        <template slot-scope="scope">
          {{ $t(scope.row.usineTypeOneName) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('用印类型(二级)')" align="center" show-overflow-tooltip prop="usineTypeTwoName">
        <template slot-scope="scope">
          <span v-if="scope.row.source === '' || scope.row.source === null || scope.row.source === undefined">
            {{ $t(scope.row.usineTypeTwoName) }}
          </span>
          <span v-else>
            {{ $t(scope.row.usineTypeTwo) }}
          </span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('关联合同')" align="center" prop="contractAssociatedName" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.contractAssociatedName }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('归档附件(个)')" align="center" :show-overflow-tooltip="true" width="150">
        <template slot-scope="scope">
          <el-link v-if="scope.row.actStatus && scope.row.actStatus === 'W' " type="primary" @click="uploadArchivedFile(scope.row)">{{ scope.row.archivedFileList.length > 0 ? scope.row.archivedFileList.length : 0 }}</el-link>
          <span v-else v-html="0" />
        </template>
      </el-table-column>
      <!--<el-table-column label="印章类型" align="center" prop="sealType" />-->
      <el-table-column :label="$t('审批状态')" fixed="right" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus ref="processStatus" :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="200px">
        <template slot-scope="scope">
          <!-- 启动流程，终止流程，修改，删除 四个按钮 -->
          <ListBtn :bus-data="scope.row" has-permi="oa:seal" />
          <template v-if="scope.row.actStatus && scope.row.actStatus === 'W' ">
            <el-button
              v-hasPermi="['oa:seal:edit']"
              size="small"
              type="text"
              icon="el-icon-upload"
              @click="uploadArchivedFile(scope.row)"
            >{{ $t('上传归档附件') }}</el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用印申请对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm">
      <oaSealForm ref="oaSealForm" />
    </el-dialog>
    <!-- 添加或归档附件对话框 -->
    <el-dialog title="上传归档附件" :visible.sync="uploadFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm">
      <uploadArchivedFileForm ref="uploadArchivedFileForm" />
    </el-dialog>
    <!-- 流程详情 -->
    <el-dialog :visible.sync="infoOpen" :title="$t('流程详情')" :destroy-on-close="true" custom-class="dialogForm" style=" text-align: left;" append-to-body :close-on-click-modal="false" :lock-scroll="false">
      <ProcessInfoForm ref="processInfoForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listOaSeal, delOaSeal } from '@/api/oa/seal/oaSeal'
import ProcessStatus from '@/components/Act/ProcessStatus'
import oaSealForm from './oaSealForm.vue'
import uploadArchivedFileForm from './uploadArchivedFileForm.vue'
import ProcessInfoForm from '@/views/act/process/processInfoForm'
export default {
    components: {
        ProcessInfoForm,
        oaSealForm,
        ProcessStatus,
        uploadArchivedFileForm
    },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 日期范围
      dateRange: [],
      // 用印申请表格数据
      oaSealList: [],
      // 弹出层标题
      title: '用印申请',
      // 是否显示弹出层
      formOpen: false,
      // 上传归档附件弹出层
      uploadFormOpen: false,
      // 查询参数
      queryParams: {
        applyUserId: '',
        userName: undefined,
        applyTime: undefined,
        contractAssociatedName: undefined,
        projectOrFund: undefined,
        pageNum: 1,
        pageSize: 10
      },
      infoOpen: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
      }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询用印申请列表 */
    getList() {
      this.loading = true
      listOaSeal(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.oaSealList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            applyUserId: undefined,
            applyTime: undefined,
            usineTypeOne: undefined,
            usineTypeTwo: undefined,
            contractAssociated: undefined,
            projectOrFund: undefined,
            sealType: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.oaSealForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.oaSealForm.init(row)
        })
    },
    // 从流程查看
    startProcess(row) {
      if (row.actId) {
        this.infoOpen = true
        this.$nextTick(() => {
          var proData = {}
          proData.actId = row.actId
          this.$refs.processInfoForm.init(proData)
        })
      } else {
        this.$message.error(this.$t('流程ID为空,不能查看流程信息'))
      }
    },
    /** 上传归档附件 */
    uploadArchivedFile(row) {
      this.uploadFormOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.uploadArchivedFileForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delOaSeal(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.downLoadExcel('/seal/oaSeal/export', this.queryParams)
    }
  }
}
</script>
